home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 41.zip / BS1 part 41 / Devpac 2.12 disk 1.adf / examples / freemem2.s < prev    next >
Text File  |  1988-10-06  |  5KB  |  201 lines

  1.  
  2. * file examples/freemem2.s - Workbench version
  3.  
  4. * a sample Intuition program to display a window constantly showing
  5. * the free memory figure, until it's closed
  6.  
  7. * this source code (C) HiSoft 1987 All Rights Reserved
  8.  
  9. * both source and binary are FreeWare and may be distributed free of charge
  10. * so long as copyright messages are not removed
  11.  
  12. * revision history:
  13. * 7th June 86    written
  14. * 22nd Sept 86    changed includes
  15. * 18th Dec 86    uses easystart for workbench version
  16.  
  17. * ensure case dependent and debug
  18.     opt    c+,d+
  19.  
  20. * firstly get the required constants and macros
  21.     incdir    ":include/"
  22.  
  23.     include    intuition/intuition.i
  24.     include    intuition/intuition_lib.i
  25.     include    exec/exec_lib.i
  26.     include    graphics/graphics_lib.i
  27.     include    exec/memory.i
  28.     include    libraries/dos_lib.i
  29.     include    libraries/dos.i
  30.  
  31.     include    misc/easystart.i
  32.  
  33. * constant for frequency of re-display
  34. timeout    equ    25                in 50ths of a second
  35.  
  36. * firstly open the intuition library
  37.     lea    intname(pc),a1
  38.     moveq    #0,d0                dont care which version
  39.     CALLEXEC OpenLibrary
  40.     tst.l    d0
  41.     beq    goawayfast            if didnt open
  42.  
  43.     move.l    d0,_IntuitionBase        store lib pointer
  44.  
  45. * and open the graphics library
  46.     lea    grafname(pc),a1
  47.     moveq    #0,d0
  48.     CALLEXEC OpenLibrary
  49.     tst.l    d0
  50.     beq    goawaycloseint
  51.     move.l    d0,_GfxBase
  52.  
  53. * and open a DOS library
  54.     lea    dosname(pc),a1
  55.     moveq    #0,d0
  56.     CALLEXEC OpenLibrary
  57.     tst.l    d0
  58.     beq    goawayclosegraf
  59.     move.l    d0,_DOSBase
  60.  
  61. * open a window next
  62.     lea    windowdef(pc),a0
  63.     CALLINT    OpenWindow
  64.     tst.l    d0
  65.     beq    goawaycloseall            if no window
  66.     move.l    d0,windowptr            store the pointer
  67.  
  68.     move.l    #-1,oldfreemem
  69.  
  70. * the main loop - display the figure, then wait, then loop
  71. mainloop
  72.     moveq    #MEMF_PUBLIC,d1
  73.     CALLEXEC AvailMem            get the figure
  74.  
  75. * got free mem, see if changed since last time
  76.     cmp.l    oldfreemem,d0
  77.     beq    messagetest            dont print if the same
  78.  
  79.     move.l    d0,oldfreemem
  80.  
  81. * free memory in d0.l, so convert to a hex string
  82. * converting to decimal is left as an exercise to the reader!
  83.  
  84.     lea    thestring(pc),a0
  85.     bsr    hexconvert
  86.  
  87. * replace leading zeros with spaces
  88.     lea    thestring(pc),a0
  89.     moveq    #7-1,d0                max to do
  90. convspaces
  91.     cmp.b    #'0',(a0)
  92.     bne.s    noconvspaces
  93.     move.b    #' ',(a0)+
  94.     dbf    d0,convspaces            convert them
  95. noconvspaces
  96.  
  97. * move the cursor to a suitable place
  98.     moveq    #4,d0                x posn
  99.     moveq    #20,d1                y posn
  100.     move.l    windowptr(pc),a1
  101.     move.l    wd_RPort(a1),a1            get rastport for window
  102.     CALLGRAF Move
  103.  
  104. * and print the string
  105.     move.l    windowptr(pc),a1
  106.     move.l    wd_RPort(a1),a1
  107.     lea    thestring(pc),a0        string
  108.     moveq    #thestringlen,d0        length
  109.     CALLGRAF Text
  110.  
  111. * now see if a message is waiting for me
  112. messagetest
  113.     move.l    windowptr(pc),a0
  114.     move.l    wd_UserPort(a0),a0        windows message port
  115.     CALLEXEC GetMsg
  116.     tst.l    d0
  117.     beq.s    nomessage
  118. * there was a message, which in our case must be CLOSEWINDOW,
  119. * so we should reply then go away
  120.     move.l    d0,a1
  121.     CALLEXEC ReplyMsg
  122.     bra.s    closewindow
  123.  
  124. * no messages waiting, so suspend myself for a short while then
  125. * do it all agaun
  126. nomessage
  127.     move.l    #timeout,d1
  128.     CALLDOS    Delay                wait a while
  129.     bra    mainloop
  130.  
  131. * close clicked so close the window
  132. closewindow
  133.     move.l    windowptr(pc),a0
  134.     CALLINT    CloseWindow
  135.  
  136. * close all the libraries
  137. goawaycloseall
  138.     move.l    _DOSBase,a1
  139.     CALLEXEC CloseLibrary
  140.  
  141. * close the graphics library
  142. goawayclosegraf
  143.     move.l    _GfxBase,a1
  144.     CALLEXEC CloseLibrary
  145.  
  146. * finished so close Intuition library
  147. goawaycloseint
  148.     move.l    _IntuitionBase,a1
  149.     CALLEXEC CloseLibrary
  150.  
  151. goawayfast
  152.     moveq    #0,d0
  153.     rts
  154.  
  155. * convert d0.l into a string at (a0) onwards in hex
  156. hexconvert
  157.     moveq    #8-1,d1            digit count
  158. hexclp    rol.l    #4,d0
  159.     move.l    d0,d2            save it
  160.     and.b    #$f,d0
  161.     cmp.b    #9,d0
  162.     ble.s    hexdig
  163.     addq.b    #7,d0
  164. hexdig    add.b    #'0',d0
  165.     move.b    d0,(a0)+        do a digit
  166.     move.l    d2,d0            restore long
  167.     dbf    d1,hexclp        do all of the digits
  168.     rts
  169.  
  170.  
  171. * window definition here
  172. windowdef    dc.w    50,50            x posn, y posn
  173.     dc.w    200,25                width,height
  174.     dc.b    -1,-1                default pens
  175.     dc.l    CLOSEWINDOW            easy IDCMP flag
  176.     dc.l    WINDOWDEPTH!WINDOWCLOSE!SMART_REFRESH!ACTIVATE!WINDOWDRAG
  177.     dc.l    0                no gadgets
  178.     dc.l    0                no checkmarks
  179.     dc.l    windowtitle            title of window
  180.     dc.l    0                no screen
  181.     dc.l    0                no bitmap
  182.     dc.w    0,0,0,0                minimum, irrelevant as no sizing gadget
  183.     dc.w    WBENCHSCREEN            in workbench
  184.  
  185. * strings here
  186. intname        INTNAME                name of intuition lib
  187. grafname    GRAFNAME            name of graphics library
  188. dosname        DOSNAME                name of dos library
  189.  
  190. windowtitle    dc.b    ' ',$a9,' HiSoft 1987 ',0
  191. thestring    dc.b    '00000000 bytes free'
  192. thestringlen    equ    *-thestring
  193.  
  194. * variables here
  195. _IntuitionBase    dc.l    0            for int library
  196. _GfxBase    dc.l    0            for graphics library
  197. _DOSBase    dc.l    0            for dos library
  198. windowptr    dc.l    0            for window ptr
  199. oldfreemem    dc.l    0            for freemem
  200.  
  201.